{{ define "search/search.html" }}
  {{ template "headereasy" . }}

  <div class="jumbotron" align="center">
    <h1>搜索引擎</h1>
  </div>
  <div class="row" style="margin: 10px 10px;">
    <div class="col-lg-8">
      <div class="input-group">
        <div class="input-group-btn">
          <!-- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action <span class="caret"></span></button> -->
          <!-- <ul class="dropdown-menu">
              <li><a href="#">Action</a></li>
              <li><a href="#">Another action</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
          </ul> -->
            {{ if .Indexes }}
            <select class="btn btn-default dropdown-toggle" id="select">
              {{ range .Indexes }}
                  <option value="{{ .UID }}">{{ .UID }}</option>
              {{ end }}
            </select>
            {{ else }}
            <select class="btn btn-default dropdown-toggle">
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
            </select>
            {{ end }}
        </div><!-- /btn-group -->
        <input type="text" id="content" class="form-control" aria-label="..." onkeydown="onKeyDown(event)">
      </div><!-- /input-group -->
    </div><!-- /.col-lg-6 -->
    <div class="col-lg-2">
      <!-- {{ .Searchdata }} -->
      {{ if .Searchdata }}
        <p class="bg-info">搜索结果：{{ .Searchdata.NbHits }}</p>
      {{ else }}
      <p class="bg-danger">搜索结果: 0</p>
      {{ end }}
    </div>
    <div class="col-lg-2">
      <p class="bg-danger">耗时: {{ .Elapsed }}</p>
    </div>
  </div><!-- /.row -->
  <div class="row" style="margin: 30px 30px;">
    {{ if .Searchdata }}
      <ul class="list-group">
        {{ range .Searchdata.Hits }}
          <li>
            <div class="panel panel-success">
              <div class="panel-heading">TITLE {{ .uid }}</div>
              <div class="panel-body">
                <div class="row">
                  <div class="col-lg-8">
                    <ul class="nav nav-pills nav-stacked">
                      {{ range $key,$value := . }}
                      <li>
                        <h2>{{ $key }} {{ $value }}</h2>
                      </li>
                      {{ end }}
                    </ul>
                  </div>
                  <div class="col-lg-4">
                    <a href="{{.poster}}" class="thumbnail">
                      <img class="media-object" src="{{ .poster }}" alt="{{.title}}">
                    </a>
                  </div>
                </div>
              </div>
            </div>
          </li>
        {{ end }}
      </ul>
    {{ end }}
  </div>
  <script type="text/javascript">
    $(document).ready(function(){
      var idx = getQueryVariable("index");
      if (idx !== undefined) {
        $('#select').val(idx);
      }
      var content = getQueryVariable("content");
      if (content !== undefined) {
        $('#content').val(content);
      }
    })
    function onKeyDown(event) {
      var e = event || window.event || arguments.callee.caller.arguments[0];
      if (e && e.keyCode == 27) { // 按Esc
        console.log('key 27 down')
      }
      if (e && e.keyCode==13) {
        var idx = $('#select').val();
        var content = $('#content').val();
        var url = window.location.pathname + '?index=' + idx + '&content=' + content
        console.log('url ' + url)
        window.location.href = url
      }
    }
    function getQueryVariable(variable)
    {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
              var pair = vars[i].split("=");
              if(pair[0] == variable){return pair[1];}
      }
      return(false);
    }
  </script>
  {{ template "footer" . }}
{{ end }}